package com.zl.credit.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zl.credit.entity.CreditProgress;
import com.zl.credit.mapper.CreditProgressMapper;
import com.zl.credit.service.CreditProgressService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author anonymous
 * @since 2020-07-14
 */
@Service
public class CreditProgressServiceImpl extends ServiceImpl<CreditProgressMapper, CreditProgress> implements CreditProgressService {

    @Autowired
    private  CreditProgressMapper progressMapper;
    @Override
    public CreditProgress selectprogress(String cpname) {
        //1.查询当前用户是否已经有正在申请的业务
        QueryWrapper<CreditProgress> wrapper = new QueryWrapper<>();
        HashMap<String, Object> map = new HashMap<>();
        map.put("CP_NAME", cpname);
        map.put("AUDIT_STATUS", "审核中");
        wrapper.allEq(map);

        CreditProgress progress = progressMapper.selectOne(wrapper);
        return progress;
    }

    @Override
    public CreditProgress selectprogressstatus(String cpname) {
        QueryWrapper<CreditProgress> wrapper = new QueryWrapper<>();
        HashMap<String, Object> map = new HashMap<>();
        map.put("CP_NAME", cpname);
        map.put("AUDIT_STATUS", "未审核");
        wrapper.allEq(map);

        CreditProgress progress = progressMapper.selectOne(wrapper);
        return progress;
    }

    @Override
    public void addprogress(String cpname) {
        //生成主键
        String substring = UUID.randomUUID().toString().substring(0, 6);
        CreditProgress progress= new CreditProgress();
        progress.setCpName(cpname);
        progress.setAuditStatus("未审核");
        progress.setAuditProgress("未申请");
        progress.setRights(0);
        progressMapper.insert(progress);
    }

    @Override
    public void updateprogress(CreditProgress progress) {
        progressMapper.updateById(progress);
    }

    @Override
    public List<CreditProgress> Queryprogress(String name) {
        QueryWrapper<CreditProgress> wrapper = new QueryWrapper<>();
        wrapper.eq("cp_name",name);
        List<CreditProgress> list = progressMapper.selectList(wrapper);
        return list;
    }
}
